# -- coding: utf-8 --
from Testing1901.unittest_demo1 import TestCal1
from Testing1901.unittest_demo2 import TestCal2
from Testing1901 import unittest_demo1
from Testing1901 import unittest_demo2
import unittest
import HTMLTestRunner

if __name__ == '__main__':
    suite = unittest.TestSuite()
    # testcases1 = unittestdemo.TestLoader().loadTestsFromModule(unittest_demo1)    #导入的模块
    # testcases2 = unittestdemo.TestLoader().loadTestsFromModule(unittest_demo2)
    testcases1 = unittest.TestLoader().loadTestsFromModule(TestCal1())  # 导入的是类, 记得实例化
    testcases2 = unittest.TestLoader().loadTestsFromModule(TestCal2())
    suite.addTests((testcases1, testcases2))
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

    # suite =unittestdemo.TestSuite()
    # # testcase1 = unittestdemo.TestLoader().loadTestsFromName('unittest_demo1.TestCal1')    #模块字符串
    # # testcase2 = unittestdemo.TestLoader().loadTestsFromName('unittest_demo2.TestCal2')
    # # suite.addTests([testcase1, testcase2])
    #
    # testcases = unittestdemo.TestLoader().loadTestsFromNames(['unittest_demo1.TestCal1','unittest_demo2.TestCal2']) #元组或者列表
    # suite.addTest(testcases)
    # # runner = unittestdemo.TextTestRunner(verbosity=2)
    # # runner.run(suite)
    #
    # #使用HTMLTestRunner生成测试报告
    # # f = open('result.html', 'wb')
    # # runner = HTMLTestRunner.HTMLTestRunner(stream=f,title='测试报告',verbosity=2, description='计算器测试情况:')
    # # runner.run(suite)
    # # f.close()
    #
    # with open('result.html', 'wb') as f:
    #     runner = HTMLTestRunner.HTMLTestRunner(stream=f, title='测试报告', verbosity=2, description='计算器测试情况:')
    #     runner.run(suite)
